﻿<%@ Page Language="C#" MasterPageFile="~/App_form/Menu/dao_tao.master" AutoEventWireup="true" CodeFile="Phong.aspx.cs" Inherits="App_form_KTX_Phong" %>

<%@ Register TagPrefix="Control" TagName="menu_phai" Src="~/App_ctr/Admin/menu_phai.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">

    <div style="width: 100%">
        <div style="width: 20%; float: left;">
            <Control:menu_phai runat="server" ID="menuphai" />
        </div>
        <div style="width: 79.4%; float: right;">
            <div style="background-image: url(../../CSS/images/ui-bg_glass_75_e6e6e6_1x400.png); font-weight: bold; height: 30px; border: 1px solid #d3d3d3; margin-top: 4px; text-align: center; padding-top: 8px; text-transform: uppercase;">
                Thông tin phòng kí túc xá
            </div>
            <div id="ndung" style="padding: 40px; margin-top: 2px;">
                <div style="display: table; margin: 0 auto; width: 90%; border: 1px solid #d3d3d3; font-size: 16px;">
                    <div style="background-image: url(../../Images/Hethong/back.gif); background-repeat: repeat-x; height: 30px; font-size: 12px !important;"></div>
                    <div style="padding: 20px;">
                        <div id="ndung_ct" class="clearfix">
                            <div style="width: 59%; float: left; margin-top: 90px;">
                                <div style="float: left; width: 30%;">
                                    <label>
                                        Nhà / Dãy  :
                                    </label>
                                </div>
                                <div>
                                    <Lib:drop runat="server" CssClass="combo panel" ID="NHA" Height="25px" Width="280px" 
                                    DataTextField="TEN" DataValueField="MA" 
                                    onClientChange="P_NHA_CHANG()" />
                                </div>
                                <div style="width: 100%; height: 6px;"></div>
                                <div style="float: left; width: 30%;">
                                    <label>
                                        Tên phòng:
                                    </label>
                                </div>
                                <div>
                                    <Lib:textBox runat="server" ID="TEN" Width="280px" Msg="Tên phòng" />
                                </div>
                                <div style="width: 100%; height: 6px;"></div>
                                <div style="float: left; width: 30%;">
                                    <label>
                                        Tổng số giường:
                                    </label>
                                </div>
                                <div>
                                    <Lib:textBox runat="server" ID="GIUONG" Width="280px" Msg="Giường" />
                                </div>
                            </div>
                            <div style="width: 40%; float: left;">
                                <Lib:gridView runat="server" ID="lke_phong" Width="360" Height="300" onClientCellClick="PHONG_CELL_CLICK">
                                    <Columns>
<%--                                        <Lib:Column Hidden="true" BaseColumn="MA" Name="MA" Width="120" />--%>
                                        <Lib:Column BaseColumn="TenNha" Name="Nhà/Dãy" Width="120" />
                                        <Lib:Column BaseColumn="TEN" Name="Tên" Width="120" />
                                         <Lib:Column BaseColumn="GIUONG" Name="Số giường" Width="120" />
                                    </Columns>
                                    <Pager>
                                        <Lib:Pager PageSize="10" />
                                    </Pager>
                                </Lib:gridView>
                            </div>
                        </div>
                        <div style="width: 100%; height: 30px;"></div>
                        <div style="margin-left: 100px;">
                            <Lib:Button runat="server" ID="add" Text="Lưu" Width="100px" onClientClick="P_PHONG_NH()"></Lib:Button>
                            <Lib:Button runat="server" ID="new" Text="Mới" Width="100px" onClientClick="P_PHONG_MOI()"></Lib:Button>
                            <Lib:Button runat="server" ID="del" Text="Xóa" Width="100px" onClientClick="P_PHONG_XOA()"></Lib:Button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <asp:HiddenField runat="server" ID="ma1" Value="0" />
    <script type="text/javascript">
        function P_NHA_CHANG() {
            try {
                $("#<%=ma1.ClientID%>").val("0");
                var nha = $("#<%=NHA.ClientID%>").val();
                if (nha == "")
                    return;
                wht_nsd.FKTX_PHONG_LKE(nha, P_PHONG_LKE_KQ, ErrorDb, ErrorTimeOut);
            }
            catch (e) {
                ShowError(e.message);
            }
        }
        function P_PHONG_LKE_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            P_PHONG_MOI();
            var grid = GetGridByID("<%=lke_phong.ClientID%>");
            grid.dataBin(b_kq);
            $("#<%=TEN.ClientID%>").focus();
        }
        function P_PHONG_MOI() {
            ResetForm("ndung_ct");
            $("#<%=ma1.ClientID%>").val("0");
            $("#<%=TEN.ClientID%>").focus();
        }

        function P_PHONG_NH() {
            try {
                var ma = $("#<%=ma1.ClientID%>").val(),
                ten = $("#<%=TEN.ClientID%>").val(),
                giuong = $("#<%=GIUONG.ClientID%>").val(),
                nha = $("#<%=NHA.ClientID%>").val();
                wht_nsd.FKTX_PHONG_NH(nha, ma, ten,giuong, P_PHONG_NH_KQ, ErrorDb, ErrorTimeOut);
            }
            catch (e) {
                Msg.Show("Thông báo", e.message, "error");
            }
        }
        function P_PHONG_NH_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            var a_kq = b_kq.split("#");
            var grid = GetGridByID("<%=lke_phong.ClientID%>");
            grid.dataBin(a_kq[1]);
            var ma = a_kq[0];
            $("#<%=ma1.ClientID%>").val(ma);
            var b_hang = grid.getRowIndex(["MA"], [ma], ["=="]);
            if (b_hang >= 0)
                grid.setActiveRow(b_hang);
        }

        //ACTIVE ROW
        function PHONG_CELL_CLICK(row, cell, val) {
            try {
                var grid = GetGridByID("<%=lke_phong.ClientID%>");
                var aVal = grid.getValueActive(["MA", "TEN", "GIUONG"]);
                if (aVal.MA == "") {
                    P_PHONG_MOI();
                    return;
                }
                $("#<%=ma1.ClientID%>").val(aVal.MA);
                $("#<%=TEN.ClientID%>").val(aVal.TEN);
                $("#<%=GIUONG.ClientID%>").val(aVal.GIUONG);
            }
            catch (e)
            { Msg.Show("Thông báo", e.message, "error"); }
        }

        function P_PHONG_XOA() {
            try {
                var ma = $("#<%=ma1.ClientID%>").val(),
                nha = $("#<%=NHA.ClientID%>").val();
                if (ma == "") {
                    Msg.ShowError(e.message);
                    return;
                }
                wht_nsd.FKTX_PHONG_XOA(nha, ma, P_PHONG_XOA_KQ, ErrorDb, ErrorTimeOut);
            }
            catch (e) {
                ShowError(e.message);
            }
        }
        function P_PHONG_XOA_KQ(b_kq) {
            if (CheckError(b_kq)) {
                ShowError(b_kq);
                return;
            }
            var grid = GetGridByID("<%=lke_phong.ClientID%>");
            grid.dataBin(b_kq);
            var ma = $("#<%=ma1.ClientID%>").val()
            var b_hang = grid.getRowIndex(["MA"], [ma], ["<"]);
            if (b_hang >= 0)
                grid.setActiveRow(b_hang);
            $("#<%=TEN.ClientID%>").val("");
            $("#<%=GIUONG.ClientID%>").val("");
            $("#<%=ma1.ClientID%>").val("0");
        }
    </script>
</asp:Content>
